<?php session_start();?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
</head>
<body>
<script LANGUAGE="javascript">
function redirectPageComplete()
{	
	alert("บันทึกประเภทสินค้าหลักสำเร็จ");
	location = "../../mainCategories.php";
}

function redirectPageIncomplete()
{
	alert("เกิดข้อผิดพลาดในการเพิ่มข้อมูล");
	location = "../../mainCategories.php";
}

function redirectPageIsnull()
{
	alert("ข้อมูลบางส่วนยังเป็น่ค่าว่าง กรุณาลงใหม่อีกครั้ง");
	location = "../../mainCategories.php";
	
}

<?php
include '../../../inc/reuse/dbconfig.php';

$id = $_POST['mainCategory_id'];
$main = $_POST['mainCategory_main'];
if(isset($main) && $id != ""){
	$sql = "UPDATE fix_main_products_type
			SET fix_main_products_type_name = '$main'			 
			WHERE fix_main_products_type_id= $id";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}
}
else
{
	$sql = "INSERT INTO fix_main_products_type (fix_main_products_type_id,fix_main_products_type_name)
	VALUES (null,'$main')";
	if(mysql_query($sql)){
		echo "redirectPageComplete();";
	}else{
		echo "redirectPageIncomplete();";
	}	
}
mysql_close();
?>
</script>
</body>
</html>
